package com.bazaar.campus;

import jakarta.annotation.Resource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication(scanBasePackages = "com.bazaar.campus")
public class HelloApplication {
    @Resource
    private ConfigurableApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(HelloApplication.class, args);
    }

    @EventListener(ApplicationReadyEvent.class)
    public void onApplicationReady() {
        String applicationName = applicationContext.getEnvironment()
                                                   .getProperty("spring.application.name");
        System.out.println(applicationName + " started ✧⁺⸜(๑˙▾˙๑)⸝⁺✧");
    }

    @RestController
    @RequestMapping
    public static final class HelloController {
        @GetMapping("/")
        public String hello() {
            return "hello world!!!";
        }
    }
}
